package dataAccess;

import java.sql.ResultSet;
import java.sql.SQLException;

import exception.MyException;

import logic.Agency;

public class AgencyDB {

	public Agency getData() throws MyException{
		DBManager dbm = null;
		Agency a = null;
		try {
			dbm = new DBManager();
		} catch (MyException e1) {
			throw e1;
		}
		String sql = "select idAgency, user, password from immconfig";
		try {
			ResultSet rs = dbm.executeAndReturn(sql);
			if (rs != null){
				rs.next();
				int idAgency = rs.getInt(1);
				String userCode = rs.getString(2);
				String userPwd = rs.getString(3);
				a = new Agency(idAgency,userCode,userPwd);
			}	
		} catch (SQLException e) {
			throw new MyException("Error en la Base datos al recorrer registro.");
		}catch (MyException e) {
			throw e;
		}finally{
			dbm.close();
		}		
		return a; 
	} 
}
